<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Security-Policy"
        content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';">

    <title>文件预览</title>
</head>

<body>
    <div id="output">加载中...</div>
    <script>
        window.MyAPI.onDisplayFile((event, fileData) => {
            const output = document.getElementById('output');
            if (fileData.type === 'text') {
                output.innerHTML = `<pre>${fileData.content}</pre>`;
            } else if (fileData.type === 'image') {
                output.innerHTML = `<img src="file://${fileData.path}" width="100%">`;
            } else if (fileData.type === 'video') {
                output.innerHTML = `<video src="file://${fileData.path}" width="100%" controls></video>`;
            } else {
                output.innerHTML = `<p>无法预览该文件: ${fileData.path}</p>`;
            }
        });
    </script>
</body>

</html>